// FindAll.h : main header file for the FindAll DLL
//

#pragma once

#ifndef __AFXWIN_H__
	#error "include 'stdafx.h' before including this file for PCH"
#endif

#include "resource.h"		// main symbols


#define ETL_FRAME_CLASS_NAME FindAll

#include "etlframe.h"
#include "resource.h"
#include "plugin.h"
#include "FindResultDialog.h"

INT_PTR CALLBACK FindDlgProc( HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam );

class FindAll
	:public CETLFrame<FindAll>
{
public:
	// _loc.dll in MUI sub folder?
	enum { _USE_LOC_DLL			= LOC_USE_PLUGIN_DLL	};

	// string ID
	enum { _IDS_MENU			= IDS_SEARCH_MENU_TEXT	};   // name of command, menu
	enum { _IDS_STATUS			= IDS_SEARCH_MENU_TEXT	};   // description of command, status bar
	enum { _IDS_NAME			= IDS_SEARCH_MENU_TEXT	};   // name of plug-in, plug-in settings dialog box
	enum { _IDS_VER				= IDS_PLUGIN_VERSION	};   // version string of plug-in, plug-in settings dialog box

	enum { _IDB_BITMAP			= IDB_BITMAP			};
	enum { _IDB_16C_24			= IDB_16C_24			};
	enum { _IDB_256C_16_DEFAULT = IDB_TRUE_16_DEFAULT	};
	enum { _IDB_256C_16_HOT		= IDB_TRUE_16_HOT		};
	enum { _IDB_256C_16_BW		= IDB_TRUE_16_BW		};
	enum { _IDB_256C_24_DEFAULT = IDB_TRUE_24_DEFAULT	};
	enum { _IDB_256C_24_HOT		= IDB_TRUE_24_HOT		};
	enum { _IDB_256C_24_BW		= IDB_TRUE_24_BW		};
	enum { _IDB_TRUE_16_DEFAULT = IDB_TRUE_16_DEFAULT	};
	enum { _IDB_TRUE_16_HOT		= IDB_TRUE_16_HOT		};
	enum { _IDB_TRUE_16_BW		= IDB_TRUE_16_BW		};
	enum { _IDB_TRUE_24_DEFAULT = IDB_TRUE_24_DEFAULT	};
	enum { _IDB_TRUE_24_HOT		= IDB_TRUE_24_HOT		};
	enum { _IDB_TRUE_24_BW		= IDB_TRUE_24_BW		};

	// masks
	enum { _MASK_TRUE_COLOR		= CLR_NONE				};
	enum { _MASK_256_COLOR		= CLR_NONE				};

	// whether to allow a file is opened in the same window group during the plug-in execution.
	enum { _ALLOW_OPEN_SAME_GROUP = TRUE				};

	// whether to allow multiple instances.
	enum { _ALLOW_MULTIPLE_INSTANCES = TRUE				};

	// supporting EmEditor newest version * 1000
	enum { _MAX_EE_VERSION		= 11000					};

	// supporting EmEditor oldest version * 1000
	enum { _MIN_EE_VERSION		= 10000					};

	// supports EmEditor Professional
	enum { _SUPPORT_EE_PRO		= TRUE					};

	// supports EmEditor Standard
	enum { _SUPPORT_EE_STD		= TRUE					};

	// user-defined members
	enum { IDW_LIST	= 100 };

	LRESULT QueryUninstall( HWND hwnd )
	{
		return 0;
	}

	LRESULT SetUninstall( HWND hwnd, LPTSTR, LPTSTR )
	{
		return 0;
	}

	LRESULT SetProperties( HWND hwnd )
	{
		return 0;
	}

	LRESULT QueryProperties( HWND hwnd )
	{
		return 0;
	}

	LRESULT UseDroppedFiles( HWND hwnd )
	{
		return 0;
	}

	LRESULT DisableAutoComplete( HWND hwnd )
	{
		return 0;
	}

	LRESULT PreTranslateMessage( HWND hwnd, MSG*)
	{
		return 0;
	}

	BOOL QueryStatus( HWND /*hwndView*/, LPBOOL pbChecked )
	{		
		*pbChecked = (m_hDlg != NULL);
		return TRUE;
	}

	void OnEvents( HWND hwndView, UINT nEvent, LPARAM lParam )
	{
		if( nEvent & EVENT_CREATE_FRAME )
		{
			//OnCommand( hwndView );
		}
		if( nEvent & EVENT_CLOSE_FRAME )
		{
			if( m_hDlg ){
				OnCommand( hwndView );
			}
		}
		if( nEvent & EVENT_CUSTOM_BAR_CLOSED )
		{
			if( m_hDlg != NULL ){  
				CUSTOM_BAR_CLOSE_INFO* pCBCI = (CUSTOM_BAR_CLOSE_INFO*)lParam;
				if( pCBCI->nID == m_nClientID ){
					CustomBarClosed();
				}
			}
		}
		if( nEvent & (EVENT_FILE_OPENED | EVENT_DOC_SEL_CHANGED) ){
		}
		if( nEvent & EVENT_CHANGE ){
		}
		if( nEvent & EVENT_CARET_MOVED ){
		}
		if( nEvent & EVENT_IDLE ){
		}
	}

	void OnCommand( HWND /*hwndView*/ )
	{
		if( m_hDlg == NULL )
		{
			m_hDlg = CreateDialog( EEGetLocaleInstanceHandle(), MAKEINTRESOURCE( IDD_FINDDIALOG ), m_hWnd, FindDlgProc );

			if( m_hDlg != NULL ){
				CUSTOM_BAR_INFO cbi;
				ZeroMemory( &cbi, sizeof( cbi ) );
				cbi.cbSize = sizeof( cbi );
				cbi.hwndClient = m_hDlg;
				cbi.iPos = 0;
				cbi.pszTitle = _T("Find All");
				m_nClientID = Editor_CustomBarOpen( m_hWnd, &cbi );

				if( !m_nClientID ){
					CustomBarClosed();
				}
				else {
					ShowWindow( m_hDlg, SW_SHOW );

					// The parent window is set to the custom bar window.
					_ASSERTE( cbi.hwndCustomBar && GetParent( m_hDlg ) == cbi.hwndCustomBar );
				}
			}
		}
		else {
			_ASSERTE( m_nClientID );
			Editor_CustomBarClose( m_hWnd, m_nClientID );
			CustomBarClosed();
		}
	}

	void CustomBarClosed()
	{
		close_searchresultdlg();
		if( m_hDlg ){
			if( IsWindow( m_hDlg ) ){
				DestroyWindow( m_hDlg );
			}
			_ASSERT( !IsWindow( m_hDlg ) );
			m_hDlg = NULL;
			m_nClientID = 0;
		}
	}

	BOOL myPreTranslateMessage( HWND /*hwndView*/, MSG* pMsg )
	{
		HWND hwndFocus = GetFocus();
		if( hwndFocus ){
			if( m_hDlg && IsChild( m_hDlg, hwndFocus ) ){
				if( pMsg->message == WM_KEYDOWN ){
					bool bCtrl = GetKeyState( VK_CONTROL ) < 0;
					bool bShift = GetKeyState( VK_SHIFT ) < 0;
					if( !bCtrl ){
						if( pMsg->wParam == VK_ESCAPE ){
							if( !bShift ){
								Editor_ExecCommand( m_hWnd, EEID_ACTIVE_PANE );
								return TRUE;
							}
						}
					}
				}
				if( IsDialogMessage( m_hDlg, pMsg ) ){
					return TRUE;
				}
			}
		}
		return FALSE;
	}

	FindAll()
		:m_hDlg(0)
		,m_nClientID(0)
		,m_ptr_dlg(0)
	{
		;
	}

	void search( HWND parent_hwnd );

	void open_searchresultdlg( HWND parent_hwnd );
	void close_searchresultdlg();

protected:

	HWND m_hDlg;
	UINT m_nClientID;

	FindResultDialog * m_ptr_dlg;
};

// the following line is needed after CMyFrame definition
_ETL_IMPLEMENT



// CFindAllApp
// See FindAll.cpp for the implementation of this class
//

class CFindAllApp : public CWinApp
{
public:
	CFindAllApp();

// Overrides
public:
	virtual BOOL InitInstance();
	virtual int ExitInstance();

	DECLARE_MESSAGE_MAP()
};
